﻿@model List<HmPMer.Entity.PayRateInfo>
@{

    var user = HmPMer.AgentUI.Models.ModelCommon.GetUserModel();
    var DLRate = new HmPMer.Business.RateBll().GetPayRateList(user.UserId, 4);
}
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-responsive.css">
<link rel="stylesheet" type="text/css" href="/static/css/bootstrap-overrides.css">
<link rel="stylesheet" type="text/css" href="/static/css/lib/font-awesome.css">

<link rel="stylesheet" type="text/css" href="/static/css/layout.css">
<link rel="stylesheet" type="text/css" href="/static/css/elements.css">
<link rel="stylesheet" type="text/css" href="/static/css/icons.css">
<link rel="stylesheet" type="text/css" href="/static/css/css.css">
<link rel="stylesheet" type="text/css" href="/static/css/compiled/user-profile.css" media="screen" />

<script src="/static/js/jquery-1.8.3.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/theme.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script src="/static/js/base.js"></script>

<style>
    .withdraw {
        float: left;
        width: 250px;
    }
</style>

<div class="container-fluid">
    <div id="pad-wrapper" class="form-page">

        <div class="row-fluid head">
            <div class="span12">
                <h4>设置商户费率</h4>
            </div>
        </div>
        @if (Model.Count > 0 && DLRate.Count > 0)
        {
            foreach (var item in Model)
            {
                var DLR = DLRate.Find(a => a.PayCode.Equals(item.PayCode));
                <div class="row-fluid withdraw">
                    <span>@(item.PayName) <span style="color:red;">(@((DLR.Rate * 100).ToString("0.00"))%)</span>：</span>
                    <input class="span3" type="text" paycode="@item.PayCode" name="inputrate" dlrate="@(DLR.Rate)" payname="@item.PayName" value="@(HM.Framework.Utils.DelNum0((item.Rate * 100).ToString()))" /><span style="color:red;">(%)</span>
                </div>
            }
        }
        else
        {
            <div class="row-fluid withdraw" style="text-align:center">
                请先设置支付类型
            </div>
        }
        <br /><br /><br /><br /><br /><br />
        <div class="row-fluid withdraw" style="text-align:center">
            <div class="span11 field-box actions" style="text-align:center">
                <input type="button" class="btn-glow primary" id="btn_submit" value="确认提交" style="margin-left:150px;">
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        //提交数据
        $("#btn_submit").click(function () {

            var bool = true;

            var listmodel = [];

            //循环获取值
            $("input[name=inputrate]").each(function (a, b) {
                var model = {};
                var reg = /^[1-9]\d*(\.\d{1,2})?$|^[0]\.\d{1,2}$/g;
                var paycoe = $(b).attr("paycode");
                var PayRate = $(b).val();
                var DLrate = $(b).attr("dlrate");
                if (parseFloat(PayRate) != 0) {

                    if (!reg.test(PayRate)) {
                        layer.msg($(b).attr("payname") + "费率只能是2位小数！");
                        $(b).focus();
                        bool = false;
                        return false;
                    }

                    if (parseFloat(PayRate) < parseFloat(DLrate*100)) {
                        layer.msg($(b).attr("payname") + "费率不能小于成本费率(" + DLrate*100+")%！");
                        $(b).focus();
                        bool = false;
                        return false;
                    }

                    if (parseFloat(PayRate) >= 100) {
                        layer.msg($(b).attr("payname") + "费率只能小于100！");
                        $(b).focus();
                        bool = false;
                        return false;
                    }
                }
                model.ChannelId = $(b).attr("paycode");
                model.Rate = PayRate;
                listmodel.push(model);
            });

            if (bool) {

                $.HM.ajax("Business/SetPayRate", {
                    data: {
                        ListModel: listmodel,
                        UserId: '@Request["UserId"]'
                    },
                    type: "POST",
                    dataType: 'json',
                    success: function (d) {
                        if (d.IsSuccess) {
                            layer.msg("设置成功", { icon: 1 });
                            setTimeout(function () {
                                window.parent.location.reload();
                            }, 1500);

                        } else {
                            layer.msg(d.message, { icon: 0 });
                        }
                    }
                });

            }

        });
    });
</script>